#!/bin/bash

sudo apt install -y curl wget ca-certificates lsb-release debian-archive-keyring \
software-properties-common aptitude apt-file

ins_llvm() {
    curl -fsSL https://apt.llvm.org/llvm-snapshot.gpg.key | gpg --dearmor |
        sudo tee /usr/share/keyrings/llvm-snapshot.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/llvm-snapshot.gpg] \
https://mirrors.tuna.tsinghua.edu.cn/llvm-apt/$(lsb_release -cs) llvm-toolchain-bullseye main" |
        sudo tee /etc/apt/sources.list.d/llvm.list
}

ins_nginx() {
    #curl -fsSL https://nginx.org/keys/nginx_signing.key | gpg --dearmor |
        #sudo tee /usr/share/keyrings/nginx-archive-keyring.gpg >/dev/null

    #echo "deb [signed-by=/usr/share/keyrings/nginx-archive-keyring.gpg] \
#https://nginx.org/packages/debian $(lsb_release -cs) nginx" |
        #sudo tee /etc/apt/sources.list.d/nginx.list

    curl -fsSL https://mirrors.tuna.tsinghua.edu.cn/nginx.io/public.key | gpg --dearmor |
        sudo tee /usr/share/keyrings/nginx-io.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/nginx-io.gpg] \
https://mirrors.tuna.tsinghua.edu.cn/nginx.io/ $(lsb_release -cs) main" |
        sudo tee /etc/apt/sources.list.d/nginx-io.list
}

ins_redis() {
    curl -fsSL https://packages.redis.io/gpg | gpg --dearmor |
        sudo tee /usr/share/keyrings/redis-archive-keyring.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] \
https://packages.redis.io/deb $(lsb_release -cs) main" |
        sudo tee /etc/apt/sources.list.d/redis.list
}

ins_mariadb() {
    version=10.6

    curl -fsSL https://mariadb.org/mariadb_release_signing_key.asc | gpg --dearmor |
        sudo tee /usr/share/keyrings/mariadb-release.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/mariadb-release.gpg, arch=amd64,i386,arm64,ppc64el] \
https://mirrors.tuna.tsinghua.edu.cn/mariadb/repo/$version/debian $(lsb_release -cs) main" |
        sudo tee /etc/apt/sources.list.d/mariadb.list
}

ins_microsoft() {
    curl -fsSL https://packages.microsoft.com/keys/microsoft.asc | gpg --dearmor |
        sudo tee /usr/share/keyrings/microsoft.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/microsoft.gpg, arch=amd64,arm64,armhf] \
https://packages.microsoft.com/repos/code stable main" |
        sudo tee /etc/apt/sources.list.d/vscode.list

    echo "deb [signed-by=/usr/share/keyrings/microsoft.gpg, arch=amd64,arm64,armhf] \
https://packages.microsoft.com/repos/edge stable main" |
        sudo tee /etc/apt/sources.list.d/microsoft-edge.list
}

ins_docker() {
    curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor |
        sudo tee /usr/share/keyrings/docker-ce.gpg >/dev/null

    echo "deb [signed-by=/usr/share/keyrings/docker-ce.gpg, arch=amd64,arm64,armhf,ppc64el] \
https://mirrors.tuna.tsinghua.edu.cn/docker-ce/linux/debian $(lsb_release -cs) stable" |
        sudo tee /etc/apt/sources.list.d/docker-ce.list
}

ins_nginx
ins_llvm
ins_redis
ins_mariadb
ins_microsoft
ins_docker

sudo apt update
sudo apt upgrade
